Add fix and test for #3224
authorMartin Hafskjold Thoresen <martinhath@gmail.com>
Tue, 25 Oct 2016 18:52:47 +0000 (20:52 +0200)
committerMartin Hafskjold Thoresen <martinhath@gmail.com>
Tue, 25 Oct 2016 18:52:47 +0000 (20:52 +0200)
src/cargo/ops/cargo_rustc/layout.rs
tests/build.rs

index f96ce5715d82be130d9b60038b51647c0c2b6769..18ae026e19396d1447ca38e643d50b7402179754 100644 (file)
@@ -50,7 +50,7 @@ use std::io;
 use std::path::{PathBuf, Path};
 
 use core::{Package, Workspace};
-use util::{Config, FileLock, CargoResult, Filesystem};
+use util::{Config, FileLock, CargoResult, Filesystem, human};
 use util::hex::short_hash;
 use super::Unit;
 
@@ -78,7 +78,8 @@ impl Layout {
         // the target triple as a Path and then just use the file stem as the
         // component for the directory name.
         if let Some(triple) = triple {
-            path.push(Path::new(triple).file_stem().unwrap());
+            path.push(try!(Path::new(triple).file_stem()
+                           .ok_or(human(format!("target was empty")))));
         }
         path.push(dest);
         Layout::at(ws.config(), path)
index 739a5b9c46799f177c65ebec8bded179eb9483bc..5b235842576f0d58c463ad53ee039f007375ce3b 100644 (file)
@@ -2374,3 +2374,15 @@ fn no_warn_about_package_metadata() {
                        .with_stderr("[..] foo v0.0.1 ([..])\n\
                        [FINISHED] debug [unoptimized + debuginfo] target(s) in [..]\n"));
 }
+
+#[test]
+fn cargo_build_empty_target() {
+    let p = project("foo")
+        .file("Cargo.toml", &basic_bin_manifest("foo"))
+        .file("src/main.rs", "fn main() {}");
+    p.build();
+
+    assert_that(p.cargo_process("build").arg("--target").arg(""),
+                execs().with_status(101)
+                .with_stderr_contains("[..] target was empty"));
+}